<?php

class db{
   
    public static $url = 'mysql:host=localhost;dbname=php';
    public static $user = 'root';
    const pwd = 'root';
    public function __construct($url,$user,$pwd){
        $this->conn = new PDO($url,$user,$pwd);
      $this->conn->setAttribute(PDO::ATTR_AUTOCOMMIT,0);
      $this->conn->beginTransaction();
        $this->conn->exec("SET NAMES UTF8");
    }
   
    public function query($sql){
       
       return $this->conn->prepare($sql);
       
    }
    
    public function commit(){
        
         
         $this->conn->setAttribute(PDO::ATTR_AUTOCOMMIT,1);
    }
    
}

$conn = new db(db::$url,db::$user,db::pwd);

$sql = "insert into user(username,password) values('王亮','1'),('王亮1','2')";
//$sql = "select * from user where username in (:username)";
$ps = $conn->query($sql);
//$ps->bindValue('username','王');
$ps->execute();
$conn->commit();
//echo count($ps->fetchAll());

echo mb_strlen('中國几十块大家风范的解放军', 'utf-8') > 5 ? mb_substr('中國几十块大家风范的解放军', 0, 5, 'utf-8').'....' : '几块几十块大家风范的解放军';
